package com.zhsj.OkeHomeConsumption.ui.activity.citypartner.mvp;

import android.content.Context;

import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.OkeHomeConsumptionApi;
import com.zhsj.OkeHomeConsumption.network.HttpClient;
import com.zhsj.OkeHomeConsumption.network.JsonResponseHandler;
import com.zhsj.OkeHomeConsumption.other.TimeChecker;
import com.zhsj.OkeHomeConsumption.other.URLEntity;
import com.zhsj.OkeHomeConsumption.ui.activity.wallet.ProgressDrawableAlertDialog;
import com.zhsj.OkeHomeConsumption.ui.activity.wallet.TimeOutHandler;
import com.zhsj.OkeHomeConsumption.utils.SignUtil;

import java.util.HashMap;

/**
 * * <p>文件描述：城市合伙人装企招募详情页面<p>
 */
public class AddEnterprisePresenter {
    public AddEnterpriseUIInterFace mUIInterFace;
    private ProgressDrawableAlertDialog pDialogUtils = null;
    public TimeChecker timeChecker;

    public AddEnterprisePresenter(Context mContext, AddEnterpriseUIInterFace uiInterface) {
        mUIInterFace = uiInterface;
        pDialogUtils = new ProgressDrawableAlertDialog(mContext);
        timeChecker = new TimeChecker(TimeOutHandler.timeOutHandler, Constants.TIME_OUT);
    }

    /**
     *添加商装企信息
     *
     *
     * {"province":"省id"},{"conuty":"是id"},{"provinceName":"北京市"},
     * {"conutyName":"北京市-北京市-东城区"},{"companyName":"公司名称"},
     * {"address":"公司地址"},{"legalPerson":"法人代表"},{"companyContacts":"联系人"},
     * {"mobile":"17610601002"},{"aera":"120"},{"companyCreateTime":"2019-10-18"},
     * {"partnership":"5"}
     *
     * @param
     * @return 创建时间：2017/2/28 11:37
     */
    public void UploadPost(final String lifeCityCopartnerDTO) {
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        final HashMap<String, String> mLogOnHashMap = new HashMap<String, String>();
        mLogOnHashMap.put("v", Constants.APPVERSION);
        mLogOnHashMap.put("t", Constants.TIME);
        mLogOnHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mLogOnHashMap.put("client", Constants.CLIENT);
        mLogOnHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mLogOnHashMap.put("platform", Constants.PLAFORM);

        mLogOnHashMap.put("partner",lifeCityCopartnerDTO);
        paramMaps.put("partner",lifeCityCopartnerDTO);


        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        pDialogUtils.show();
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mLogOnHashMap);
        HttpClient.posttwo(OkeHomeConsumptionApi.ELVDOU_PARTNERREGISTER, lifeCityCopartnerDTO, new JsonResponseHandler() {
            @Override
            public void onSuccess(int statusCode, String content) {
                super.onSuccess(statusCode, content);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                mUIInterFace.UploadPost(content);
            }
            @Override
            public void onFailure(Throwable e) {
                super.onFailure(e);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
            }
        });
    }


    /**
     * 获取城市列表
     *
     * @param
     */
    public void CityListPsot() {
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        final HashMap<String, String> mLogOnHashMap = new HashMap<String, String>();
        mLogOnHashMap.put("v", Constants.APPVERSION);
        mLogOnHashMap.put("t", Constants.TIME);
        mLogOnHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mLogOnHashMap.put("client", Constants.CLIENT);
        mLogOnHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mLogOnHashMap.put("platform", Constants.PLAFORM);
        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        pDialogUtils.show();
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mLogOnHashMap);
        HttpClient.get(OkeHomeConsumptionApi.ELVDOU_QUERYDISTRICT+ "?isType=" + "1" , paramMaps, new JsonResponseHandler() {
            @Override
            public void onSuccess(int statusCode, String content) {
                super.onSuccess(statusCode, content);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                mUIInterFace.CityListPsot(content);
            }

            @Override
            public void onFailure(Throwable e) {
                super.onFailure(e);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
            }
        });
    }



}
